﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace D3crft.Windows.UserControls {
    /// <summary>
    /// Interaktionslogik für ucCharacterEditor.xaml
    /// </summary>
    public partial class ucCharacterEditor : UserControl {

        public event EventHandler evStatChanged;

        private Characters.ClassObjects.ocCharacter oEditingCharacter = null;

        private int iSelectedIndex = 0;

        public ucCharacterEditor() {
            InitializeComponent();

            PropertyTextbox_0.evTextChanged += ev_PropertyTextBox_IntTextChanged;
            PropertyTextbox_1.evTextChanged += ev_PropertyTextBox_IntTextChanged;
            PropertyTextbox_2.evTextChanged += ev_PropertyTextBox_IntTextChanged;
            PropertyTextbox_3.evTextChanged += ev_PropertyTextBox_IntTextChanged;
        }

        public void SetEditingCharacter(Characters.ClassObjects.ocCharacter oCharacter) {
            hide_TabControls(iSelectedIndex);
            oEditingCharacter = oCharacter;
            load_TabValues(iSelectedIndex);
            show_TabControls(iSelectedIndex);
        }

        private void select_Item(int iIndex) {
            // deselect old
            if (iSelectedIndex > -1) {
                get_ItemBorderByIndex(iSelectedIndex).Background = Application.Current.FindResource("Gradient_GreyLight") as Brush;
                get_ItemLabelByIndex(iSelectedIndex).Foreground = Application.Current.FindResource("Brush_DefaultForeground") as Brush;
                hide_TabControls(iSelectedIndex);
            }
            iSelectedIndex = iIndex;
            get_ItemBorderByIndex(iSelectedIndex).Background = Application.Current.FindResource("Gradient_BlueMid") as Brush;
            get_ItemLabelByIndex(iSelectedIndex).Foreground = Application.Current.FindResource("Brush_PressedForeground") as Brush;
            load_TabValues(iIndex);
            show_TabControls(iIndex);
        }

        private void load_TabValues(int iIndex) {
            switch (iIndex) {
                case 0:
                    PropertyTextbox_0.Text = oEditingCharacter.iBaseStat_Strength.ToString();
                    PropertyTextbox_1.Text = oEditingCharacter.iBaseStat_Dexterity.ToString();
                    PropertyTextbox_2.Text = oEditingCharacter.iBaseStat_Intelligence.ToString();
                    PropertyTextbox_3.Text = oEditingCharacter.iBaseStat_Vitality.ToString();
                    break;
                case 1:
                    PropertyTextbox_0.Text = oEditingCharacter.fOffStat_AttackSpeedInrease.ToString("N1", CultureInfo.InvariantCulture);
                    PropertyTextbox_1.Text = oEditingCharacter.fOffStat_CritChance.ToString("N1", CultureInfo.InvariantCulture);
                    PropertyTextbox_2.Text = oEditingCharacter.fOffStat_CritDamage.ToString("N1", CultureInfo.InvariantCulture);
                    PropertyTinyTextbox_0.Text = oEditingCharacter.iOffStat_BonusDamage_Min.ToString();
                    PropertyTinyTextbox_1.Text = oEditingCharacter.iOffStat_BonusDamage_Max.ToString();
                    break;
                case 2:
                    PropertyTextbox_0.Text = oEditingCharacter.fWeaponStats_MHDPS.ToString("N1", CultureInfo.InvariantCulture).Replace(",", string.Empty);
                    PropertyTinyTextbox_0.Text = oEditingCharacter.fWeaponStats_MHAPS.ToString("N2", CultureInfo.InvariantCulture);

                    if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Barbarian) {
                        PropertyTextbox_1.Text = (oEditingCharacter as Characters.ClassObjects.ocBarbarian).fWeaponStats_OHDPS.ToString("N1", CultureInfo.InvariantCulture).Replace(",", string.Empty);
                        PropertyTinyTextbox_1.Text = (oEditingCharacter as Characters.ClassObjects.ocBarbarian).fWeaponStats_OHAPS.ToString("N2", CultureInfo.InvariantCulture);
                        PropertyCheckbox.Checked = (oEditingCharacter as Characters.ClassObjects.ocBarbarian).bWeaponStat_Dualwield;
                    } else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Demon_Hunter) {
                        PropertyTextbox_1.Text = (oEditingCharacter as Characters.ClassObjects.ocDemonHunter).fWeaponStats_OHDPS.ToString("N1", CultureInfo.InvariantCulture).Replace(",", string.Empty);
                        PropertyTinyTextbox_1.Text = (oEditingCharacter as Characters.ClassObjects.ocDemonHunter).fWeaponStats_OHAPS.ToString("N2", CultureInfo.InvariantCulture);
                        PropertyCheckbox.Checked = (oEditingCharacter as Characters.ClassObjects.ocDemonHunter).bWeaponStat_Dualwield;
                    } else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Monk) {
                        PropertyTextbox_1.Text = (oEditingCharacter as Characters.ClassObjects.ocMonk).fWeaponStats_OHDPS.ToString("N1", CultureInfo.InvariantCulture).Replace(",", string.Empty);
                        PropertyTinyTextbox_1.Text = (oEditingCharacter as Characters.ClassObjects.ocMonk).fWeaponStats_OHAPS.ToString("N2", CultureInfo.InvariantCulture);
                        PropertyCheckbox.Checked = (oEditingCharacter as Characters.ClassObjects.ocMonk).bWeaponStat_Dualwield;
                    }
                    break;
                case 3:
                    PropertyTextbox_0.Text = oEditingCharacter.iOtherStat_PhysicalBonus.ToString();
                    PropertyTextbox_1.Text = oEditingCharacter.iOtherStat_ArcaneBonus.ToString();
                    PropertyTextbox_2.Text = oEditingCharacter.iOtherStat_ColdBonus.ToString();
                    PropertyTextbox_3.Text = oEditingCharacter.iOtherStat_FireBonus.ToString();
                    PropertyTextbox_4.Text = oEditingCharacter.iOtherStat_HolyBonus.ToString();
                    PropertyTextbox_5.Text = oEditingCharacter.iOtherStat_LighteningBonus.ToString();
                    PropertyTextbox_6.Text = oEditingCharacter.iOtherStat_PoisonBonus.ToString();
                    break;
                    
                default:

                    break;
            }
        }

        private void save_TextValueToCharacter(ucTextBox oTextBox) {
            //return;
            bool bTemp = false;
            switch (iSelectedIndex) {
                case 0:
                    if (oTextBox.Equals(PropertyTextbox_0)) {
                        // strength
                        oEditingCharacter.iBaseStat_Strength = int.Parse(oTextBox.Text);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTextbox_1)) {
                        // dexterity
                        oEditingCharacter.iBaseStat_Dexterity = int.Parse(oTextBox.Text);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTextbox_2)) {
                        // intelligence
                        oEditingCharacter.iBaseStat_Intelligence = int.Parse(oTextBox.Text);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTextbox_3)) {
                        // vitality
                        oEditingCharacter.iBaseStat_Vitality = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    break;
                case 1:
                    if (oTextBox.Equals(PropertyTextbox_0)) {
                        // attackspeed
                        oEditingCharacter.fOffStat_AttackSpeedInrease = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTextbox_1)) {
                        // crit chance
                        oEditingCharacter.fOffStat_CritChance = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTextbox_2)) {
                        // crit damage
                        oEditingCharacter.fOffStat_CritDamage = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTinyTextbox_0)) {
                        // bonus dmg min
                        oEditingCharacter.iOffStat_BonusDamage_Min = int.Parse(oTextBox.Text);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTinyTextbox_1)) {
                        // bonus dmg max
                        oEditingCharacter.iOffStat_BonusDamage_Max = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    break;
                case 2:
                    if (oTextBox.Equals(PropertyTextbox_0)) {
                        // mh dps
                        oEditingCharacter.fWeaponStats_MHDPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTinyTextbox_0)) {
                        // mh aps
                        oEditingCharacter.fWeaponStats_MHAPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                        bTemp = true;
                    } else if (oTextBox.Equals(PropertyTextbox_1)) {
                        // oh dps
                        if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Barbarian) {
                            (oEditingCharacter as Characters.ClassObjects.ocBarbarian).fWeaponStats_OHDPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                            bTemp = true;
                        }
                        else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Demon_Hunter) {
                            (oEditingCharacter as Characters.ClassObjects.ocDemonHunter).fWeaponStats_OHDPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                            bTemp = true;
                        }
                        else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Monk) {
                            (oEditingCharacter as Characters.ClassObjects.ocMonk).fWeaponStats_OHDPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                            bTemp = true;
                        }
                    } else if (oTextBox.Equals(PropertyTinyTextbox_1)) {
                        // oh aps
                        if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Barbarian) {
                            (oEditingCharacter as Characters.ClassObjects.ocBarbarian).fWeaponStats_OHAPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                            bTemp = true;
                        }
                        else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Demon_Hunter) {
                            (oEditingCharacter as Characters.ClassObjects.ocDemonHunter).fWeaponStats_OHAPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                            bTemp = true;
                        }
                        else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Monk) {
                            (oEditingCharacter as Characters.ClassObjects.ocMonk).fWeaponStats_OHAPS = float.Parse(oTextBox.Text, CultureInfo.InvariantCulture);
                            bTemp = true;
                        }
                    }
                    break;
                case 3:
                    if (oTextBox.Equals(PropertyTextbox_0)) {
                        // physical bonus
                        oEditingCharacter.iOtherStat_PhysicalBonus = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    else if (oTextBox.Equals(PropertyTextbox_1)) {
                        // arcane bonus
                        oEditingCharacter.iOtherStat_ArcaneBonus = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    else if (oTextBox.Equals(PropertyTextbox_2)) {
                        // cold bonus
                        oEditingCharacter.iOtherStat_ColdBonus = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    else if (oTextBox.Equals(PropertyTextbox_3)) {
                        // fire bonus
                        oEditingCharacter.iOtherStat_FireBonus = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    else if (oTextBox.Equals(PropertyTextbox_4)) {
                        // holy bonus
                        oEditingCharacter.iOtherStat_HolyBonus = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    else if (oTextBox.Equals(PropertyTextbox_5)) {
                        // lightening bonus
                        oEditingCharacter.iOtherStat_LighteningBonus = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    else if (oTextBox.Equals(PropertyTextbox_6)) {
                        // poison bonus
                        oEditingCharacter.iOtherStat_PoisonBonus = int.Parse(oTextBox.Text);
                        bTemp = true;
                    }
                    break;
                default:

                    break;
            }
            if (bTemp) {
                // stat changed, now fire event
                if (evStatChanged != null) evStatChanged(this, EventArgs.Empty);
            }
        }

        private void save_CheckValueToCharacter(ucCheckBox oCheckBox) {
            bool bTemp = false;

            switch (iSelectedIndex) {
                case 2:

                    if (oCheckBox.Equals(PropertyCheckbox)) {
                        // dualwield
                        if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Barbarian) {
                            (oEditingCharacter as Characters.ClassObjects.ocBarbarian).bWeaponStat_Dualwield = oCheckBox.Checked;
                            bTemp = true;
                        }
                        else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Demon_Hunter) {
                            (oEditingCharacter as Characters.ClassObjects.ocDemonHunter).bWeaponStat_Dualwield = oCheckBox.Checked;
                            bTemp = true;
                        }
                        else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Monk) {
                            (oEditingCharacter as Characters.ClassObjects.ocMonk).bWeaponStat_Dualwield = oCheckBox.Checked;
                            bTemp = true;
                        }
                    }
                    break;
                default:

                    break;
            }
            if (bTemp) {
                // stat changed, now fire event
                if (evStatChanged != null) evStatChanged(this, EventArgs.Empty);
            }
        }

        private int get_IndexFromBorder(Border oBorder) {
            return int.Parse(oBorder.Name.Split('_')[1]);
        }

        private Border get_ItemBorderByIndex(int iIndex) {
            switch (iIndex) {
                case 0:
                    return Border_0;
                case 1:
                    return Border_1;
                case 2:
                    return Border_2;
                case 3:
                    return Border_3;
                case 4:
                    return Border_4;
                case 5:
                    return Border_5;
                case 6:
                    return Border_6;
                default:
                    return null;
            }
        }

        private Label get_ItemLabelByIndex(int iIndex) {
            switch (iIndex) {
                case 0:
                    return Label_0;
                case 1:
                    return Label_1;
                case 2:
                    return Label_2;
                case 3:
                    return Label_3;
                case 4:
                    return Label_4;
                case 5:
                    return Label_5;
                case 6:
                    return Label_6;
                default:
                    return null;
            }
        }

        private void hide_TabControls(int iIndex) {
            switch (iIndex) {
                case 0:
                    PropertyTextbox_0.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_1.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_2.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_3.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyLabel_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_2.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_3.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_2.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_3.Visibility = System.Windows.Visibility.Hidden;
                    break;
                case 1:
                    PropertyTextbox_0.evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
                    PropertyTextbox_1.evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
                    PropertyTextbox_2.evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
                    PropertyTinyTextbox_0.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTinyTextbox_1.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyLabel_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_2.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_3.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTinyLabel_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_2.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTinyTextbox_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTinyTextbox_1.Visibility = System.Windows.Visibility.Hidden;
                    break;
                case 2:
                    PropertyTextbox_0.evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
                    PropertyTextbox_1.evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
                    PropertyTinyTextbox_0.evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
                    PropertyTinyTextbox_1.evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
                    PropertyCheckbox.evCheckedChanged -= ev_PropertyCheckBox_CheckedChanged;
                    PropertyLabel_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_2.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_3.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTinyTextbox_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTinyTextbox_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyCheckbox.Visibility = System.Windows.Visibility.Hidden;
                    break;
                case 3:
                    PropertyTextbox_0.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_1.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_2.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_3.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_4.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_5.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_6.evTextChanged -= ev_PropertyTextBox_IntTextChanged;
                    PropertyLabel_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_2.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_3.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_4.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_5.Visibility = System.Windows.Visibility.Hidden;
                    PropertyLabel_6.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_1.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_2.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_3.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_4.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_5.Visibility = System.Windows.Visibility.Hidden;
                    PropertyTextbox_6.Visibility = System.Windows.Visibility.Hidden;
                    break;
                default:
                    break;
            }
        }

        private void show_TabControls(int iIndex) {
            switch (iIndex) {
                case 0:
                    PropertyLabel_0.Content = "Strength:";
                    PropertyLabel_1.Content = "Dexterity:";
                    PropertyLabel_2.Content = "Intelligence:";
                    PropertyLabel_3.Content = "Vitality:";
                    PropertyLabel_0.Margin = new Thickness(145, 0, 55, 200);
                    PropertyLabel_1.Margin = new Thickness(145, 35, 55, 165);
                    PropertyLabel_2.Margin = new Thickness(145, 70, 55, 130);
                    PropertyLabel_3.Margin = new Thickness(145, 105, 55, 95);
                    PropertyTextbox_0.Margin = new Thickness(225, 0, -25, 200);
                    PropertyTextbox_1.Margin = new Thickness(225, 35, -25, 165);
                    PropertyTextbox_2.Margin = new Thickness(225, 70, -25, 130);
                    PropertyTextbox_3.Margin = new Thickness(225, 105, -25, 95);

                    PropertyTextbox_0.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_1.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_2.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_3.evTextChanged += ev_PropertyTextBox_IntTextChanged;

                    PropertyLabel_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_2.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_3.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_1.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_2.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_3.Visibility = System.Windows.Visibility.Visible;
                    break;
                case 1:
                    PropertyLabel_0.Content = "Attackspeed increase:";
                    PropertyLabel_1.Content = "Criticall hit chance:";
                    PropertyLabel_2.Content = "Critical hit damage:";
                    PropertyLabel_3.Content = "Bonus damage:";
                    PropertyTinyLabel_0.Content = "-";
                    PropertyLabel_0.Margin = new Thickness(130, 0, 70, 200);
                    PropertyLabel_1.Margin = new Thickness(130, 35, 70, 165);
                    PropertyLabel_2.Margin = new Thickness(130, 70, 70, 130);
                    PropertyLabel_3.Margin = new Thickness(130, 105, 70, 95);
                    PropertyTextbox_0.Margin = new Thickness(240, 0, -40, 200);
                    PropertyTextbox_1.Margin = new Thickness(240, 35, -40, 165);
                    PropertyTextbox_2.Margin = new Thickness(240, 70, -40, 130);
                    PropertyTinyLabel_0.Margin = new Thickness(257, 103, -57, 97);
                    PropertyTinyTextbox_0.Margin = new Thickness(223, 105, -23, 95);
                    PropertyTinyTextbox_1.Margin = new Thickness(290, 105, -90, 95);

                    PropertyTextbox_0.evTextChanged += ev_PropertyTextBox_FloatTextChanged;
                    PropertyTextbox_1.evTextChanged += ev_PropertyTextBox_FloatTextChanged;
                    PropertyTextbox_2.evTextChanged += ev_PropertyTextBox_FloatTextChanged;
                    PropertyTinyTextbox_0.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTinyTextbox_1.evTextChanged += ev_PropertyTextBox_IntTextChanged;

                    PropertyLabel_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_2.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_3.Visibility = System.Windows.Visibility.Visible;
                    PropertyTinyLabel_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_1.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_2.Visibility = System.Windows.Visibility.Visible;
                    PropertyTinyTextbox_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyTinyTextbox_1.Visibility = System.Windows.Visibility.Visible;
                    break;
                case 2:
                    bool bDualWield = false;
                    if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Barbarian) {
                        bDualWield = (oEditingCharacter as Characters.ClassObjects.ocBarbarian).bWeaponStat_Dualwield;
                    }
                    else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Demon_Hunter) {
                        bDualWield = (oEditingCharacter as Characters.ClassObjects.ocDemonHunter).bWeaponStat_Dualwield;
                    }
                    else if (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Monk) {
                        bDualWield = (oEditingCharacter as Characters.ClassObjects.ocMonk).bWeaponStat_Dualwield;
                    }


                    PropertyLabel_0.Content = "Weapon DPS:";
                    PropertyLabel_1.Content = "Speed:";
                    PropertyLabel_0.Margin = new Thickness(145, 0, 55, 200);
                    PropertyLabel_1.Margin = new Thickness(145, 35, 55, 165);


                    PropertyTextbox_0.Margin = new Thickness(220, 0, -20, 200);
                    PropertyTinyTextbox_0.Margin = new Thickness(203, 35, -3, 165);
                    

                    PropertyLabel_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Visible;
                    
                    PropertyTinyTextbox_0.Visibility = System.Windows.Visibility.Visible;

                    if ((oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Barbarian) || (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Demon_Hunter) || (oEditingCharacter.eClass == Characters.ClassObjects.ocCharacter.eCharacterClass.Monk)) {
                        // dualwieldable?
                        PropertyLabel_2.Content = "Offhand DPS:";
                        PropertyLabel_3.Content = "Speed:";
                        PropertyLabel_2.Margin = new Thickness(145, 105, 55, 95);
                        PropertyLabel_3.Margin = new Thickness(145, 140, 55, 60);

                        PropertyCheckbox.Text = "Dualwield";
                        PropertyTextbox_1.Margin = new Thickness(220, 105, -20, 95);
                        PropertyTinyTextbox_1.Margin = new Thickness(203, 140, -3, 60);
                        PropertyCheckbox.Margin = new Thickness(115, 77, 85, 123);

                        PropertyLabel_2.Visibility = System.Windows.Visibility.Visible;
                        PropertyLabel_3.Visibility = System.Windows.Visibility.Visible;
                        PropertyTextbox_1.Visibility = System.Windows.Visibility.Visible;
                        PropertyTinyTextbox_1.Visibility = System.Windows.Visibility.Visible;
                        PropertyCheckbox.Visibility = System.Windows.Visibility.Visible;
                    }

                    if (bDualWield) {
                        PropertyLabel_0.Content = "Mainhand DPS:";
                    } else {
                        
                    }

                    PropertyTextbox_0.evTextChanged += ev_PropertyTextBox_FloatTextChanged;
                    PropertyTextbox_1.evTextChanged += ev_PropertyTextBox_FloatTextChanged;
                    PropertyTinyTextbox_0.evTextChanged += ev_PropertyTextBox_FloatTextChanged;
                    PropertyTinyTextbox_1.evTextChanged += ev_PropertyTextBox_FloatTextChanged;
                    PropertyCheckbox.evCheckedChanged += ev_PropertyCheckBox_CheckedChanged;
                    break;
                case 3:
                    PropertyLabel_0.Content = "Physical damage bonus:";
                    PropertyLabel_1.Content = "Arcane damage bonus:";
                    PropertyLabel_2.Content = "Cold damage bonus:";
                    PropertyLabel_3.Content = "Fire damage bonus:";
                    PropertyLabel_4.Content = "Holy damage bonus:";
                    PropertyLabel_5.Content = "Lightening damage bonus:";
                    PropertyLabel_6.Content = "Poison damage bonus:";
                    PropertyLabel_0.Margin = new Thickness(120, 0, 80, 200);
                    PropertyLabel_1.Margin = new Thickness(120, 35, 80, 165);
                    PropertyLabel_2.Margin = new Thickness(120, 70, 80, 130);
                    PropertyLabel_3.Margin = new Thickness(120, 105, 80, 95);
                    PropertyLabel_4.Margin = new Thickness(120, 140, 80, 60);
                    PropertyLabel_5.Margin = new Thickness(120, 175, 80, 25);
                    PropertyLabel_6.Margin = new Thickness(120, 210, 80, -10);
                    PropertyTextbox_0.Margin = new Thickness(250, 0, -50, 200);
                    PropertyTextbox_1.Margin = new Thickness(250, 35, -50, 165);
                    PropertyTextbox_2.Margin = new Thickness(250, 70, -50, 130);
                    PropertyTextbox_3.Margin = new Thickness(250, 105, -50, 95);
                    PropertyTextbox_4.Margin = new Thickness(250, 140, -50, 60);
                    PropertyTextbox_5.Margin = new Thickness(250, 175, -50, 25);
                    PropertyTextbox_6.Margin = new Thickness(250, 210, -50, -10);

                    PropertyTextbox_0.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_1.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_2.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_3.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_4.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_5.evTextChanged += ev_PropertyTextBox_IntTextChanged;
                    PropertyTextbox_6.evTextChanged += ev_PropertyTextBox_IntTextChanged;

                    PropertyLabel_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_1.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_2.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_3.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_4.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_5.Visibility = System.Windows.Visibility.Visible;
                    PropertyLabel_6.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_0.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_1.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_2.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_3.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_4.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_5.Visibility = System.Windows.Visibility.Visible;
                    PropertyTextbox_6.Visibility = System.Windows.Visibility.Visible;
                    break;
                default:
                    break;
            }
        }

        private void ev_ItemBorder_MouseEnter(object sender, MouseEventArgs ea) {
            int iIndex = get_IndexFromBorder(sender as Border);

            if (iIndex != iSelectedIndex) {
                (sender as Border).Background = Application.Current.FindResource("Gradient_GreyMid") as Brush;
            }
        }

        private void ev_ItemBorder_MouseLeave(object sender, MouseEventArgs ea) {
            int iIndex = get_IndexFromBorder(sender as Border);

            if (iIndex != iSelectedIndex) {
                (sender as Border).Background = Application.Current.FindResource("Gradient_GreyLight") as Brush;
            }
        }

        private void ev_ItemBorder_MouseUp(object sender, MouseEventArgs ea) {
            int iIndex = get_IndexFromBorder(sender as Border);

            if (iIndex != iSelectedIndex) {
                // select item
                select_Item(iIndex);
            }
        }

        private void ev_PropertyTextBox_IntTextChanged(object sender, RoutedEventArgs ea) {
            (sender as ucTextBox).evTextChanged -= ev_PropertyTextBox_IntTextChanged;
            if (scGUIFunctions.correct_INTucTextBox(sender as ucTextBox)) {
                // process it
                save_TextValueToCharacter(sender as ucTextBox);
            }
            (sender as ucTextBox).evTextChanged += ev_PropertyTextBox_IntTextChanged;
        }

        private void ev_PropertyTextBox_FloatTextChanged(object sender, RoutedEventArgs ea) {
            (sender as ucTextBox).evTextChanged -= ev_PropertyTextBox_FloatTextChanged;
            if (scGUIFunctions.correct_FLOATucTextBox(sender as ucTextBox)) {
                // process it
                save_TextValueToCharacter(sender as ucTextBox);
            }
            (sender as ucTextBox).evTextChanged += ev_PropertyTextBox_FloatTextChanged;
        }

        private void ev_PropertyCheckBox_CheckedChanged(object sender, EventArgs ea) {
            save_CheckValueToCharacter(sender as ucCheckBox);
        }
    }
}
